home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1993 September
/
September 93.iso
/
Archives
/
Fun, Tricks & Hacks
/
Silent Alarm, not!
/
SonicAlarm.h
< prev
next >
Wrap
Text File
|
1992-06-15
|
10KB
|
321 lines
#ifndef __SONICALARM__
#define __SONICALARM__
#endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// resources IDs
// STR# resources
#define kErrStrings 1000 // error string list
// error string indexes for kErrStrings
enum {
eFatalErr = 1, // fatal error, cannot continue
eNoMemory, // out of memory
eNoWindow, // couldn't create window
eNoSndInDevice, // no sound input device
eSndOutMgr, // sound ouput error
eSndInMgr, // sound input error
eSettingMeter, // could not set level metering
eFeatureNotAvailable // system to wimpy
};
// menus
// The menu IDs have an "m" prefix and item numbers have an "i" prefix.
#define rMenuBar 1000
#define mApple 128
enum {
iAbout = 1
};
#define mFile 129
enum {
iQuit = 1
};
#define mEdit 130
enum {
iUndo = 1,
iCut = 3,
iCopy,
iPaste,
iClear
};
#define mAlarm 131
enum {
iSetPassword = 1,
iActivate = 3
};
// ALRT resources
#define rAboutAlert 1000
#define rUserAlert 1001
#define rPasswordsDoNotMatch 1002
// WIND resource
#define kAlarmWindow 1000
#define kActivationWindow 1001
#define kConfigurationWindow 1002
#define kDeactivationWindow 1003
#define kSetPasswordWindow 1004
// CNTL resources
#define kCancelCountDown 1000
#define kConfigurationCancel 1001
#define kConfigurationOK 1002
#define kDeactivationOK 1003
#define kSetPasswordCancel 1004
#define kSetPasswordOK 1005
// RECT resources
#define kActivationCountRect 1000
#define kActivationMsgRect 1001
#define kConfigureLevelRect 1002
#define kTestLightRect 1003
#define kSensitivityRect 1004
#define kConfigureMsgRect 1005
#define kPasswordRect 1006
#define kDeactivationMsgRect 1007
#define kDeactivationCountRect 1008
#define kSetPasswordMsgRect 1009
#define kSetPasswordRect 1010
// STR resources
#define kActivationMessage 1000
#define kAlarmMessage 1001
#define kDeactivationMessage 1002
#define kSetPassword1Message 1003
#define kSetPassword2Message 1004
#define kConfigureMessage 1005
#define kSensitivityTitle 1006
#define kSensitivityMax 1007
#define kSensitivityMin 1008
// Strg resource (the password)
#define kPasswordResID 1000
// snd resources
#define kAlarmTriggeredSnd 1000
#define kAlarmActivatedSnd 1001
#define kAlarmDeactivatedSnd 1002
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// constants
// for some reason the Think C Traps.h file is not up to date with MPW 3.2
// this trap should have been defined, as it appears in MPW
#ifdef THINK_C
#define _SoundDispatch 0xA800 /* Sound Manager dispatch trap */
#endif
#define kMinHeap (80L*1024L) /* minimal heap size I want to run in */
#define kOSTrapBit (1<<11) /* bit 11 is the OS Trap bit */
#define kATrapBits 0xA800 /* bits used by the A-Trap mechanism */
#define kSystemSeven 0x00000700 /* gestaltSystemVersion result for System 7.0 */
#define kFatalError true /* error was fatal for AlertUser */
#define kAlarmedSleep 10 /* sleep amount while in foreground */
#define kNotAlarmedSleep MAXLONG /* sleeping amount while in background */
#define kOneSecondTicks 60 /* 60 ticks in a second */
#define kFixed100Percent 0x00010000 /* Fixed representation of 100% */
#define kNumLevelsShift 5 /* a power of 2 to determine the number of levels */
#define kNumberOfLevels (1<<kNumLevelsShift) /* number of levels in the array */
#define kPasswordResType 'Strg' /* the password resource type */
#define kLengthOfPassword 15 /* how many chars in the password */
#define kActivationDelay 10 /* alarm activation in seconds */
#define kDeactivationDelay 10 /* alarm deactivation in seconds */
#define kVisualDelay 8 /* number of ticks to delay button selection */
#define kDefaultSensitivity 80 /* default percentage of sensitivity for alarm */
#define kMimimumSensivity 30 /* minimum percentage of sensitivity allowed */
#define kSystemFontSize 0 /* default sytem font size */
#define kActivatingFontID applFont /* font used to display count down */
#define kActivatingFontSize 36 /* size of count down font */
#define kAlarmFontID applFont /* font used to display main alarm message */
#define kAlarmFontSize 48 /* size of main alarm message font */
#define kSensitivityFontSize 9 /* size of the sensitivity control font */
#define kSpaceBelowMBar 20 /* space of alarm message below Menus */
#define kEditTextInset 3 /* space inside of edit text frames */
#define kSensitivitySpace 3 /* space outside of control for titles */
#define kDITopLeft 0x00500070 /* Point position of the Disk Init dialog */
#define kIsColorPort 0xC000 /* 2 high bits set in portVersion of a CGrafPort */
#define charBullet '•' /* used to filter password chars */
enum {
kDeactivatedState = 0, /* alarm is not active */
kActivatingState, /* alarm is activating itself */
kDeactivatingState, /* alarm is being deactivated */
kConfiguringState, /* alarm is bing configured, it's a test */
kActivatedState /* alarm is activated */
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// types
typedef struct {
WindowRecord window;
StringHandle message; // message drawn while the alarm is activated
Rect msgRect; // where to draw the message
long lastTickCount; // TickCount to draw the alarmed message
short secondsCountDown;
Boolean drawWhite; // alternating colors flag
} AlarmWindow, *AlarmWindowPtr;
typedef struct {
WindowRecord window;
StringHandle message; // message drawn while the alarm is activated
Rect msgRect; // where to draw the message
Point delayPt; // where to draw the count down numbers
long lastTickCount; // TickCount to draw the alarmed message
short secondsCountDown; // the number of seconds left in the count down
} ActivationWindow, *ActivationWindowPtr;
typedef struct {
WindowRecord window;
StringHandle message; // message drawn while the alarm is deactivating
Rect msgRect; // deactivation message area
Rect passwordRect; // the user's password area
Point delayPt; // where to draw the count down numbers
long lastTickCount; // TickCount to signal the alarm
short secondsCountDown; // the number of seconds left in the count down
unsigned char password[kLengthOfPassword+1]; // password being entered, plus length
} DeactivationWindow, *DeactivationWindowPtr;
typedef struct {
WindowRecord window;
StringHandle message; // message drawn while configuring alarm
StringHandle sensitivityTitle; // title of the sensitivity control
StringHandle max; // message next to top of control
StringHandle min; // message next to bottom of control
Rect levelRect; // the volume level's area
Rect testLightRect; // the test light indicator area
Rect sensitivityRect; // the user control are
Rect msgRect; // message shown to user
short sensitivity; // user's setting of control value
long lastTickCount;
Boolean testLightOn;
} ConfigurationWindow, *ConfigurationWindowPtr;
typedef struct {
WindowRecord window;
StringHandle message; // message drawn while the alarm is deactivating
Rect msgRect; // message shown to user
Rect passwordRect; // area for password
Boolean firstPhase; // entering the password for the first time
Boolean accepted; // true if password was accepted
unsigned char password1[kLengthOfPassword+1]; // password being entered, plus length
unsigned char password2[kLengthOfPassword+1]; // password being entered, plus length
} SetPasswordWindow, *SetPasswordWindowPtr;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// macros
// Define HighWord and LowWord macros for efficiency.
#define HighWord(aLong) (((aLong) >> 16) & 0xFFFF)
#define LowWord(aLong) ((aLong) & 0xFFFF)
// accessing a rectangle's points
#define TopLeft(r) (* (Point *) &(r).top)
#define BottomRight(r) (* (Point *) &(r).bottom)
// "easy to use" methods for testing, setting, and clearing bits
#define SetBits(bits, dest) (dest |= (bits))
#define ClearBits(bits, dest) (dest &= ~(bits))
#define IsBitsAreSet(bits, dest) (dest & (bits))
#define IsBitsAreClear(bits, dest) (!(dest & (bits)))
#define DEBUG true
// This will insert debugging code in the application to check conditions
// and displays a message in the debugger if true
#ifdef DEBUG
#define FailMsg(cond) \
if (cond) { \
DebugStr((ConstStr255Param)"\p"#cond); \
}
#else
#define FailMsg(cond) \
((void) 0)
#endif
// check for the exception, and if true call the action and then goto handler
#ifdef DEBUG
#define FailIf(cond, handler) \
if (cond) { \
DebugStr((ConstStr255Param)"\p"#cond); \
goto handler; \
}
#else
#define FailIf(cond, handler) \
if (cond) { \
goto handler; \
}
#endif
// check for the exception, and if true call the action and then goto handler
#ifdef DEBUG
#define FailWithAction(cond, action, handler) \
if (cond) { \
DebugStr((ConstStr255Param)"\p"#cond); \
{ action; } \
goto handler; \
}
#else
#define FailWithAction(cond, action, handler) \
if (cond) { \
{ action; } \
goto handler; \
}
#endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// inlines
// copy a pascal string, the real way - NEVER USE _BlockMove FOR THIS !
#pragma parameter PascalStringCopy(__A0,__A1)
void PascalStringCopy(const StringPtr src, StringPtr dest) =
{0x7000, 0x1010, 0x12D8, 0x51C8, 0xFFFC};
//PascalStringCopy
// moveq #0,d0 ; clear the index register
// move.b (a0),D0 ; get string length
//Loop move.b (a0)+,(a1)+ ; copy bytes, one greater for length byte
// dbra d0,Loop ; continue until less than 0